<!DOCTYPE html>
<html lang="zh-Hans" class="io-grey-mode">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册机首页</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
    <!-- 依赖引入 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.8.17/css/layui.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.8.17/layui.min.js"></script>
    <script src="/static/js/jquery.min.js"></script>

    <style>
        body {
            font-family: 'Roboto', sans-serif;
            background-color: #f4f4f9;
            color: #333;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }
        .container {
            background: #fff;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
            max-width: 900px;
            width: 100%;
        }
        h1 {
            font-size: 2.5rem;
            color: #444;
            margin-bottom: 2rem;
            text-align: center;
        }
        ul {
            list-style-type: none;
            padding: 0;
        }
        ul li {
            margin: 1.5rem 0;
        }
        a {
            text-decoration: none;
            color: #007bff;
            font-weight: 500;
            padding: 0.5rem 1rem;
            border-radius: 6px;
            transition: background-color 0.3s ease;
        }
        a:hover {
            text-decoration: none;
            background-color: rgba(0, 123, 255, 0.1);
        }
        .section {
            margin-bottom: 2.5rem;
            padding: 1.5rem;
            background-color: #f9f9f9;
            border-radius: 8px;
        }
        .section-title {
            font-size: 1.75rem;
            color: #555;
            margin-bottom: 1.5rem;
            border-bottom: 2px solid #007bff;
            padding-bottom: 0.5rem;
        }
        .note {
            font-size: 0.9rem;
            color: #777;
            margin-top: 1rem;
            text-align: center;
        }
        img {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            margin-top: 1rem;
        }
        .button-container {
            display: flex;
            gap: 1rem;
            margin-top: 1rem;
        }
        .button-container a {
            background-color: #007bff;
            color: white;
            padding: 0.75rem 1.5rem;
            border-radius: 6px;
            text-align: center;
            flex: 1;
        }
        .button-container a:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>私人定制IntelliJ IDEA注册机首页</h1>
    <div style="text-align: center">
        <img src="/static/images/定制效果.png" alt="定制效果图">
    </div>
    <div style="text-align: center">定制效果图</div>
    <div class="section">
        <div class="section-title">客户使用说明</div>
        <ul>
            <li><a target="_blank" href="https://www.yuque.com/u2164145/hrr1dx/gv0sgemtpa133fyd">使用手册 访问密码：pagq</a></li>
            <li><a target="_blank" href="/static/jetbra.zip">原始压缩包下载</a></li>
            <li><a target="_blank" href="/generateLicense?licenseName=ABC">证书生成JSON版本</a></li>
            <li>
                <!-- 触发按钮 -->
                <button class="layui-btn" onclick="openFormModal()">证书生成ZIP版本</button>
            </li>
        </ul>
    </div>

    <div class="section">
        <div class="section-title">投资人使用说明</div>
        <ul>
            <li>1、不要把本网站外传，泄露</li>
            <li>2、复制<b>使用手册</b>地址给别人</li>
            <li>3、下载<b>原始压缩包下载</b>文件给别人</li>
            <li>4、点击<b>证书生成</b>，可以改参数<b>licenseName</b>生成专属JSON，自己保存txt</li>
            <li>5、生成的专属JSON与原始压缩包2份文件给别人即可</li>
        </ul>
        <div class="note">请确保遵守相关法律法规，合法使用本工具。</div>
    </div>
</div>
<script>
    layui.use(['layer', 'form', 'jquery'], function () {
        var layer = layui.layer;
        var form = layui.form;
        let $ = layui.jquery;

        // 提前绑定表单提交事件
        form.on('submit(formDemo)', function (data) {
            // 获取表单数据
            const formData = data.field;
            console.log('提交数据：', formData);

            // 此处添加AJAX提交逻辑
            //压缩包下载
            const downloadLink = document.createElement('a');
            downloadLink.href ='/zipLicense?' + $.param(data.field);
            downloadLink.style.display = 'none';
            downloadLink.setAttribute('download', 'downloaded_file_name'); // 设置下载文件名
            document.body.appendChild(downloadLink);
            downloadLink.click();
            document.body.removeChild(downloadLink);

            layer.msg('提交成功', {icon: 1});
            layer.closeAll(); // 关闭所有弹窗
            return false;
        });

        window.openFormModal = function () {
            layer.open({
                type: 1,
                title: '许可证信息提交',
                area: ['500px', '400px'],
                content: [
                    '<form class="layui-form"  lay-filter="formDemo" style="padding: 20px;">',
                    '   <div class="layui-form-item">',
                    '       <label class="layui-form-label">开关选项</label>',
                    '       <div class="layui-input-block">',
                    '           <input type="checkbox" name="switchOption" lay-skin="switch" lay-filter="switchFilter">',
                    '       </div>',
                    '   </div>',
                    '   <div class="layui-form-item licenseNameItem">',
                    '       <label class="layui-form-label">名称</label>',
                    '       <div class="layui-input-block">',
                    '           <input type="text" name="licenseName" placeholder="请输入许可证名称" autocomplete="off" class="layui-input">',
                    '       </div>',
                    '   </div>',
                    '   <div class="layui-form-item prefixItem" style="display:none;">',
                    '       <label class="layui-form-label">前缀</label>',
                    '       <div class="layui-input-block">',
                    '           <input type="text" name="prefix" placeholder="请输入前缀" autocomplete="off" class="layui-input">',
                    '       </div>',
                    '   </div>',
                    '   <div class="layui-form-item suffixItem" style="display:none;">',
                    '       <label class="layui-form-label">后缀</label>',
                    '       <div class="layui-input-block">',
                    '           <input type="text" name="suffix" placeholder="请输入后缀" autocomplete="off" class="layui-input">',
                    '       </div>',
                    '   </div>',
                    '   <div class="layui-form-item layui-form-btn">',
                    '       <div class="layui-input-block">',
                    '           <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">提交</button>',
                    '           <button class="layui-btn layui-btn-primary">取消</button>',
                    '       </div>',
                    '   </div>',
                    '</form>'
                ].join(''),
                success: function (layero) {
                    form.render(); // 渲染表单元素
                    // 监听开关变化
                    form.on('switch(switchFilter)', function (data) {
                        if (data.elem.checked) {
                            $('.licenseNameItem').val("");
                            $('.licenseNameItem').hide();
                            $('.prefixItem').show();
                            $('.suffixItem').show();
                        } else {
                            $('.licenseNameItem').show();
                            $('.prefixItem').hide();
                            $('.suffixItem').hide();
                            $('.prefixItem').val("");
                            $('.suffixItem').val("");
                        }
                        form.render();
                    });
                },
                yes: function (index, layero) {
                    // 触发提交
                    layero.find('form').submit();
                    return false;
                }
            });
        };
    });
</script>
</body>
</html>
